// house_pkg/pages/locate/index.ts
// 导入地图SDK的实例化对象
import qqMap from '../../../utils/qqmap'
Page({
  goBuilding(ev) {
    wx.navigateTo({
      url: '/house_pkg/pages/building/index?point=' + ev.mark.point,
    })
  },
  onLoad() {
    this.getLocation()
  },
  // 获取用户当前所在位置的经纬度
  async getLocation() {
    const { latitude, longitude } = await wx.getLocation()
    console.log(latitude, longitude)
    this.getPoint(latitude, longitude)
  },
  // 获取用户指定位置的经纬度
  async chooseLocation() {
    const { latitude, longitude } = await wx.chooseLocation()
    console.log(latitude, longitude)
    this.getPoint(latitude, longitude)
  },
  // 根据经纬度获取位置信息
  getPoint(latitude, longitude) {
    qqMap.reverseGeocoder({
      location: [latitude, longitude].join(','),
      success: (res) => {
        console.log(res.result.address)
        this.setData({
          address: res.result.address,
        })
        qqMap.search({
          keyword: '小区',
          location: [latitude, longitude].join(','),
          page_size: 10,
          success: (res) => {
            console.log(res)
            this.setData({
              points: res.data,
            })
          },
        })
      },
    })
  },
})
